Option Explicit

Private rng

Function init(arr)
    rng = arr
End Function

'行数组（二维）转一维数组
Function aRowtoArr() As Variant
    Dim arr(), list()
    Dim i!
    arr = rng
    If UBound(arr, 2) > UBound(arr, 1) Or UBound(arr, 2) > 1 Then: Debug.Print "aRowtoArr Err:数据不是行数组": Exit Function:
    ReDim list(UBound(arr, 1) - 1)
    For i = 0 To UBound(arr, 1) - 1
        list(i) = arr(i + 1, 1)
    Next i
    aRowtoArr = list
End Function

'列数组（二维）转一维数组
Function aColtoArr() As Variant
    Dim arr(), list()
    Dim i!
    arr = rng
    If UBound(arr, 1) > UBound(arr, 2) Or UBound(arr, 1) > 1 Then: Debug.Print "aColtoArr Err:数据不是列数组": Exit Function:
    ReDim list(UBound(arr, 2) - 1)
    For i = 0 To UBound(arr, 2) - 1
        list(i) = arr(1, i + 1)
    Next i
    aColtoArr = list
End Function

'列数组（二维）转一维数组
Function aColtoDeDuplicationArr() As Variant
    Dim arr(), list As Object
    Dim i!
    Set list = CreateObject("Scripting.Dictionary")
    arr = rng
    If UBound(arr, 1) > UBound(arr, 2) Or UBound(arr, 1) > 1 Then: Debug.Print "aColtoArr Err:数据不是列数组": Exit Function:
    For i = 0 To UBound(arr, 2) - 1
        If arr(1, i + 1) <> Empty Then
            list(arr(1, i + 1)) = Empty
        End If
    Next i
    aColtoDeDuplicationArr = list.keys
End Function

'行数组（二维）转一维数组
Function aRowtoDeDuplicationArr() As Variant
    Dim arr(), list As Object
    Dim i!
    '定义字典
    Set list = CreateObject("Scripting.Dictionary")
    arr = rng
    If UBound(arr, 2) > UBound(arr, 1) Or UBound(arr, 2) > 1 Then: Debug.Print "aRowtoArr Err:数据不是行数组": Exit Function:
    For i = 0 To UBound(arr, 1) - 1
        If arr(i + 1, 1) <> Empty Then
            list(arr(i + 1, 1)) = Empty
        End If
    Next i
    aRowtoDeDuplicationArr = list.keys
End Function

